package web
{
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	public class WebUserInput extends Sprite
	{
		public static const USER_LOGIN:String	= "userLogin";
		
		public var txtUserName:TextField;	//	用户名输入框
		public var btnLogin:SimpleButton;	//	登陆按钮
		
		public function WebUserInput()
		{
			this.txtUserName.restrict = "A-Z a-z_0-9";
			this.txtUserName.text = "Guest_user" + Math.floor(Math.random() * 999);
			this.btnLogin.addEventListener(MouseEvent.CLICK, onEnterUser);
		}
		
		public function get userName():String
		{
			return this.txtUserName.text.replace(" ","");
		}
		
		private function onEnterUser(e:MouseEvent):void
		{
			if(this.txtUserName.text.slice().replace(" ", "").length > 0)
			{
				this.dispatchEvent(new Event(USER_LOGIN));
			}
		}
		
	}
}